package com.winton.common;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.winton.model.S_USER;

public class LoginHandlerIntercepter implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
			
			
        	if(request.getServletPath().startsWith("/admin/userLogin")||request.getServletPath().startsWith("/login")){ 
        		//登录页面放行
        		return  true;
        	}           
            HttpSession session = request.getSession();              
            if((S_USER) session.getAttribute("user")!=null){  
                //登陆成功的用户  
            	return  true;  
            }  
               //没有登陆，转向登陆界面  
            response.sendRedirect(request.getContextPath() + "/login");   
            return  false;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

}
